#!/bin/sh
#   FSM template example implementation
#
#   Copyright (C) 2013 Dushara Jayasinghe.
#
#   fsm_template is free software: you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation, either version 3 of the License, or
#   (at your option) any later version.
#
#   fsm_template is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with fsm_template.  If not, see <http://www.gnu.org/licenses/>.

#
#   This is a bash script used by the Makefile for unit testing purposes
#
#   It requires 2 arguments
#       <calc cmd_args> <file_with expected outputs>
#
#   The purpose of it is the invoke the calculator and pass the provided
#   command line argument and compare it's output with the contnts of
#   the provided text file.


# Check that the first arg is not empty
if [ -n "$1" ]
then
    # Check for non-empty arg 2
    if [ -n "$2" ]
    then
        # Invoke the calculator with arg1 and capture the output
        result=`./calc $1`
        # Get the expected output
        correct=`cat $2`
        # Do they match?
        if [ "$result" != "$correct" ]
        then
            # No generate an error with the actual output
            echo "FAILED "
            echo -n "$1" -\>
            echo "$result"
            return 1
        fi
    else
        echo "missing compare string"
    fi
else
    echo "missing key press sequence"
fi
